package org.graduates.webapp.actions.course;

import java.util.Date;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.json.annotations.JSON;
import org.graduates.webapp.actions.BaseAction;
import org.projects.graduates.domain.HomeworkAssignments;
import org.projects.graduates.domain.HomeworkHandin;

/**
 * 提交作业
 * 
 * @author Administrator
 * 
 */
@Action(results = { @Result(name = "input", type = "json"), @Result(name = "success", type = "json") })
public class CommitHandinAction extends BaseAction {

	private static final long serialVersionUID = -5580621129606160808L;

	private boolean success = false;

	private long haid = 0L;

	private HomeworkHandin handin;

	public String execute() {

		if (null == handin) {
			return INPUT;
		}
		HomeworkAssignments ha = HomeworkAssignments.get(HomeworkAssignments.class, haid);
		handin.setPerson(getCurrentPerson());
		handin.setTime(new Date());
		handin.setHomework(ha);
		this.gradApplication.save(handin);
		success = true;

		return SUCCESS;

	}

	public void setHaid(long haid) {
		this.haid = haid;
	}

	public boolean isSuccess() {
		return success;
	}

	@JSON(serialize = false)
	public HomeworkHandin getHandin() {
		return handin;
	}

	public void setHandin(HomeworkHandin handin) {
		this.handin = handin;
	}

}
